//
//  YHScrollToTopButtonView.m
//  FAKER
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "YHScrollToTopButtonView.h"
#import "FitHeader.h"

@implementation YHScrollToTopButtonView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _backgroundView = [[UIView alloc] init];
    _backgroundView.backgroundColor = [UIColor blackColor];
    _backgroundView.layer.cornerRadius = self.WIDTH / 2;
    _backgroundView.layer.borderWidth = 2;
    _backgroundView.layer.borderColor = [UIColor grayColor].CGColor;
    _backgroundView.alpha = .5;
    [self addSubview:_backgroundView];
    
    _scrollToTopButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_scrollToTopButton setTitle:@"Top" forState:UIControlStateNormal];
    _scrollToTopButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
    [_scrollToTopButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_scrollToTopButton addTarget:self action:@selector(clickScrollToTopButton) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_scrollToTopButton];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _backgroundView.frame = CGRectMake(0, 0, self.WIDTH, self.HEIGHT);
    _scrollToTopButton.frame = _backgroundView.frame;
}

- (void)clickScrollToTopButton
{
    [self.delegate yhScrollToTop];
    self.hidden = YES;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
